package com.ygxsk.carhome.ui.order;

import android.annotation.SuppressLint;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.ObjectUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.Utils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.BitmapImageViewTarget;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.flyco.roundview.RoundTextView;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
import com.tencent.mmkv.MMKV;
import com.yanzhenjie.album.Action;
import com.yanzhenjie.album.Album;
import com.yanzhenjie.album.api.widget.Widget;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.alertview.AlertView;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.constant.ExtraKey;
import com.ygxsk.carhome.listener.DoubleClickListener;
import com.ygxsk.carhome.response.ShopCartApplyForImageBean;
import com.ygxsk.carhome.response.ShopCartApplyforBean;
import com.ygxsk.carhome.response.ShopCartBeanApplyForDetail;
import com.ygxsk.carhome.ui.ErrorActivity;
import com.ygxsk.carhome.ui.adapter.ApplyForDetailAdapter;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.views.MyLinearLayoutManager;

import java.math.BigDecimal;
import java.util.ArrayList;

import butterknife.BindView;

/*
 * @Author:itchenqi
 * @Time:2019/11/11 0011  10:20
 * @Description: 添加申请退货的详情界面，从订单详情的底部【退货详情】按钮进入：
 * 废弃 使用H5 但是后边不知道是不是继续用2024年2月18日09:54:11做记录
 */
public class ApplyForDetailActivity extends ErrorActivity {


    //private Session mSession;

    /**
     * 该界面的下拉布局内容
     */
    @BindView(R.id.refreshlayoutinapplydetail)
    SmartRefreshLayout refreshLayoutInapplyDetail;

    /**
     * 该界面之中填充退货商品列表的布局
     */
    @BindView(R.id.recyclerviewinapplydetail)
    RecyclerView recyclerViewInapplyDetail;

    /**
     * 取消申请的包裹布局内容
     */
    @BindView(R.id.layoutbuttoninapplydetail)
    LinearLayout layoutButtonInApplyDetail;

    /**
     * 底部取消申请按钮
     */
    @BindView(R.id.buttontcancelinapplydetail)
    RoundTextView buttontCancelInApplyDetail;

    //填充适配器的数据内容
    private ArrayList<ShopCartApplyforBean> mDatasResources = new ArrayList<>();

    //暂时和退货列表通用
    private ApplyForDetailAdapter applyForDetailAdapter;

    /**
     * 商品退货单号的  单号信息
     */
    private String returnApplyNoPass;

    /**
     * 是否是会员商品的退货退款等 如果是会员商品 就没有footer isVipOrder=1是会员商品
     */
    private int returnIsVipOrder;

    /**
     * 确定【取消申请】的二次弹窗确认
     */
    private AlertView mAlertView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        processExtraData();

        //mSession = Session.get(this);

        initloading();

        initViews();

        //测试屏蔽，真实放开
        gainDatas();

    }

    private void processExtraData() {

        Bundle bundle = this.getIntent().getExtras();

        if (bundle != null) {
            returnApplyNoPass = bundle.getString(ExtraKey.EXTRA_ORDER_RETURNAPPLYNO);
            returnIsVipOrder = bundle.getInt(ExtraKey.EXTRA_ORDER_RETURNAPPLY_ISVIPORDER);
        }

    }

    /**
     * 重写 getResources() 方法，让APP的字体不受系统设置字体大小影响
     */
    @Override
    public Resources getResources() {//还原字体大小
        Resources res = super.getResources();
        //非默认值
        if (res.getConfiguration().fontScale != 1) {
            Configuration newConfig = new Configuration();
            newConfig.setToDefaults();//设置默认
            res.updateConfiguration(newConfig, res.getDisplayMetrics());
        }
        return res;
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_apply_for_detail;
    }

    @Override
    protected void initToolBar(ToolbarHelper toolbarHelper) {

//        toolbarHelper.setLayoutSao(false, null);

        toolbarHelper.setTitle("退货详情");

        toolbarHelper.setLayoutLeft(true, R.drawable.backicon, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //checkEdit();
                methodBack();
            }
        });

        toolbarHelper.setLayoutClose(false, "", null);

        toolbarHelper.setLayoutRight(false, 0, "", null);

    }

    @Override
    protected void onClickNodata(View v) {

        gainDatas();

    }

    @Override
    protected void initViews() {


        //顶部 内容
       /* ShopCartApplyforBean shopCartBean0 = new ShopCartApplyforBean();
        shopCartBean0.setProductId("1109");
        shopCartBean0.setProductFullName("新鲜红黄彩椒甜椒圆椒柿子椒灯笼椒");
        shopCartBean0.setSalesPrice(new BigDecimal("13.00"));
        shopCartBean0.setProductCount(1);
        shopCartBean0.setLogoImg("http://wuyeapi.91dgj.com/resource/image/productLogo/20190307/2019030708461979839194.jpg");

        ShopCartApplyforBean shopCartBean1 = new ShopCartApplyforBean();
        shopCartBean1.setProductId("1110");
        shopCartBean1.setProductFullName("有机胡萝卜 新鲜蔬菜");
        shopCartBean1.setSalesPrice(new BigDecimal("12.00"));
        shopCartBean1.setProductCount(3);
        shopCartBean1.setLogoImg("http://wuyeapi.91dgj.com/resource/image/productLogo/20190307/2019030708490744138082.jpg");

        ShopCartApplyforBean shopCartBean2 = new ShopCartApplyforBean();
        shopCartBean2.setProductId("1111");
        shopCartBean2.setProductFullName("无公害小黄瓜 水果黄瓜 蔬菜新鲜");
        shopCartBean2.setSalesPrice(new BigDecimal("16.00"));
        shopCartBean2.setProductCount(5);
        shopCartBean2.setLogoImg("http://wuyeapi.91dgj.com/resource/image/productLogo/20190307/2019030708520193075721.jpg");

        mDatasResources.add(shopCartBean0);
        mDatasResources.add(shopCartBean1);
        mDatasResources.add(shopCartBean2);*/

        //中间九宫格

        //商品列表内容
        recyclerViewInapplyDetail.setLayoutManager(new MyLinearLayoutManager(this));

        //去掉动画等操作

        //填充适配器
        applyForDetailAdapter = new ApplyForDetailAdapter(R.layout.applyfordetailadapter, mDatasResources);
        recyclerViewInapplyDetail.setAdapter(applyForDetailAdapter);

        applyForDetailAdapter.notifyDataSetChanged();

        applyForDetailAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                //做消耗点击
                //LogUtils.d("itchen---->这里做条目点击的消耗");
            }
        });

        //测试代码

        //仅仅包含下拉刷新的内容
        refreshLayoutInapplyDetail.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {

                refreshLayout.getLayout().post(new Runnable() {
                    @Override
                    public void run() {

                        gainDatas();

                        refreshLayout.finishRefresh();

                    }
                });

            }
        });

        //底部的金额和退回方式

        //取消按钮
        buttontCancelInApplyDetail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (!DoubleClickListener.isFastDoubleClick()) {

                    //【取消申请】有一个二次弹窗确认，避免手滑操作
                    CommUtils.checkDialog(mAlertView);

                    mAlertView = new AlertView("",
                            "确定取消申请吗?",
                            "取消",
                            new String[]{"确定"},
                            null,
                            ApplyForDetailActivity.this,
                            AlertView.Style.Alert,
                            new com.ygxsk.carhome.alertview.OnItemClickListener() {
                                @Override
                                public void onItemClick(Object o, int position) {

                                    if (position != AlertView.CANCELPOSITION) {

//                                        method_cancelApplyfor(returnApplyNoPass);

                                    }

                                }
                            });

                    mAlertView.setCancelable(true).show();

                }

            }
        });

    }

    private View getFooterView(RecyclerView recyclerView, ShopCartBeanApplyForDetail shopCartBeanApplyForDetail) {

        View viewFooter;

        if (!ObjectUtils.isEmpty(recyclerView)) {

            viewFooter = getLayoutInflater().inflate(R.layout.footerviewinapplyfor, (ViewGroup) recyclerView.getParent(), false);

        } else {

            viewFooter = getLayoutInflater().inflate(R.layout.footerviewinapplyfor, null);//
        }

        //设置每一项
        //商品总额
        TextView textPriceTotal = (TextView) viewFooter.findViewById(R.id.textpricetotalapply);
        //优惠金额
        TextView textPriceCouponapply = (TextView) viewFooter.findViewById(R.id.textpricecouponapply);
        //退款金额
        TextView textPriceReturn = (TextView) viewFooter.findViewById(R.id.textpricereturnapply);

        //退回方式的包裹布局
        RelativeLayout layountContentReturnType = (RelativeLayout) viewFooter.findViewById(R.id.layountcontentreturntypeview);
        //退回方式
        TextView textReturnType = (TextView) viewFooter.findViewById(R.id.textreturntypeapply);


        //商品总金额
        BigDecimal amount = shopCartBeanApplyForDetail.getTotalSalePrice();

        if (amount != null) {

            CommUtils.setText(textPriceTotal, MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL, StringUtils.getString(R.string.yangjiaocurrencysymbol)) +//
                    CommUtils.formatComma2BigDecimal(amount).toString());

        } else {
            CommUtils.setText(textPriceTotal, MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL, StringUtils.getString(R.string.yangjiaocurrencysymbol)) + "0.00");
        }


        //优惠金额
        BigDecimal disAmount = shopCartBeanApplyForDetail.getDisAmount();
        if (disAmount != null) {
            CommUtils.setText(textPriceCouponapply, MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL, StringUtils.getString(R.string.yangjiaocurrencysymbol)) +//
                    CommUtils.formatComma2BigDecimal(disAmount).toString());
        } else {
            CommUtils.setText(textPriceCouponapply, MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL, StringUtils.getString(R.string.yangjiaocurrencysymbol)) +//
                    "0.00");
        }


        //退款金额
        BigDecimal returnAmount = shopCartBeanApplyForDetail.getReturnAmount();

        if (returnAmount != null) {
            CommUtils.setText(textPriceReturn, MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL, StringUtils.getString(R.string.yangjiaocurrencysymbol)) +//
                    CommUtils.formatComma2BigDecimal(returnAmount).toString());
        } else {
            CommUtils.setText(textPriceReturn, MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL, StringUtils.getString(R.string.yangjiaocurrencysymbol)) +//
                    "0.00");
        }

        if (TextUtils.equals(shopCartBeanApplyForDetail.getRefundType(), ConstantSign.PAY_DGJ)) {//91DGJ
            CommUtils.setText(textReturnType, "其他支付");
        } else if (TextUtils.equals(shopCartBeanApplyForDetail.getRefundType(), ConstantSign.PAY_ALIPAY)) {
            CommUtils.setText(textReturnType, "支付宝");
        } else if (TextUtils.equals(shopCartBeanApplyForDetail.getRefundType(), ConstantSign.PAY_WECHAT)) {
            CommUtils.setText(textReturnType, "微信");
        } else {

            //2019年 奥莱发现时零元购的类型?这句注释是从【支付界面】抄写过来的，不知道现在是否有【零元购】的方式。
            //第二种处理：
            //让整块栏目都隐藏
            layountContentReturnType.setVisibility(View.GONE);

            //第一种处理：
            CommUtils.setText(textReturnType, "");
        }

        return viewFooter;

    }

    /**
     * 获取顶部的Headerview内容
     */
    private View getHeaderView(RecyclerView recyclerView, ShopCartBeanApplyForDetail shopCartBeanApplyForDetail) {

        View viewHeader;

        if (!ObjectUtils.isEmpty(recyclerView)) {

            viewHeader = getLayoutInflater().inflate(R.layout.headerinapplydetail,//
                    (ViewGroup) recyclerView.getParent(),//
                    false);//;

        } else {

            viewHeader = getLayoutInflater().inflate(R.layout.headerinapplydetail, null);//

        }

        //填充每一项内容
        //顶部的状态内容
        TextView textviewApplyState = (TextView) viewHeader.findViewById(R.id.textviewapplystate);


        //申请单号
        TextView textviewDanNumber = (TextView) viewHeader.findViewById(R.id.textviewdannumber);

        //订单编号
        TextView textviewOrderNumber = (TextView) viewHeader.findViewById(R.id.textviewordernumber);

        //申请时间
        TextView textviewApplyTime = (TextView) viewHeader.findViewById(R.id.textviewapplytime);


        //退款时间
        LinearLayout layoutReturnMoney = (LinearLayout) viewHeader.findViewById(R.id.layoutreturnmoney);

        //申请退货的原因
        LinearLayout layoutResonCon = (LinearLayout) viewHeader.findViewById(R.id.layoutresoncon);

        //横向九宫格图片内容
        LinearLayout layoutImageList = (LinearLayout) viewHeader.findViewById(R.id.layoutimagelist);


        //TextView textviewApplyReson = (TextView) viewHeader.findViewById(R.id.textviewapplyreson);


        //TextView textviewGridLeft = (TextView) viewHeader.findViewById(R.id.textviewgridleft);


        if (shopCartBeanApplyForDetail != null) {

            //@applyState（等于0的时候可以取消申请；等于3代表退款完成，退款时间展示updateTime）

            //退货的进度：文本 也是退货状态文本。  然后根据状态判断 是否展示【退款时间】
            CommUtils.setText(textviewApplyState, shopCartBeanApplyForDetail.getApplyStateInfo());

            //申请退货单号：
            CommUtils.setText(textviewDanNumber, shopCartBeanApplyForDetail.getReturnApplyNo());

            //订单编号
            CommUtils.setText(textviewOrderNumber, shopCartBeanApplyForDetail.getOrderNo());

            //申请时间：这里是创建时间
            CommUtils.setText(textviewApplyTime, shopCartBeanApplyForDetail.getCreateTime());


            //------------------------------------------------------------------------------------------------------
            //动态展示：applyState（等于0的时候可以取消申请；等于3代表退款完成，退款时间展示updateTime）
            if (shopCartBeanApplyForDetail.getApplyState() == 3) {
                //代表退款完成，展示出来
                layoutReturnMoney.setVisibility(View.VISIBLE);

                TextView textviewRefundTime = (TextView) viewHeader.findViewById(R.id.textviewrefundtime);

                CommUtils.setText(textviewRefundTime, shopCartBeanApplyForDetail.getUpdateTime());

            } else {
                //其他状态均是隐藏掉
                layoutReturnMoney.setVisibility(View.GONE);
            }


            //------------------------------------------------------------------------------------------------------
            //申请退货的原因不是空的
            if (!TextUtils.isEmpty(shopCartBeanApplyForDetail.getReturnApplyDesc())) {

                layoutResonCon.setVisibility(View.VISIBLE);

                TextView textviewApplyReson = (TextView) viewHeader.findViewById(R.id.textviewapplyreson);
                CommUtils.setText(textviewApplyReson, shopCartBeanApplyForDetail.getReturnApplyDesc());

            } else {
                //那末 没有填写退货原因的话 就是不展示
                layoutResonCon.setVisibility(View.GONE);
            }
            //------------------------------------------------------------------------------------------------------


            //填充图片的内容
            if ((shopCartBeanApplyForDetail.getImgList() != null) && (!shopCartBeanApplyForDetail.getImgList().isEmpty())) {

                layoutImageList.setVisibility(View.VISIBLE);

                //------------------------------------------------------------------------------------------------------

                //int with = textviewGridLeft.getLayoutParams().width;
                //float with = textviewGridLeft.getLayout().getLineWidth(5);

                //float with = textviewGridLeft.getPaint().measureText("退货凭证：");
                //LogUtils.d("itchen---左侧文字的宽度是-->" + with);

                //退货的商品图片九宫格
                ArrayList<String> datas = new ArrayList<>();
                for (ShopCartApplyForImageBean bean ://
                        shopCartBeanApplyForDetail.getImgList()) {
                    datas.add(bean.getImgUrl());
                }
                //测试数据
                //datas.add("http://wuyeapi.91dgj.com/resource/image/productLogo/20190307/2019030708490744138082.jpg");
                //datas.add("http://wuyeapi.91dgj.com/resource/image/productLogo/20190307/2019030708520193075721.jpg");
                //datas.add("http://wuyeapi.91dgj.com/resource/image/productLogo/20190307/2019030708461979839194.jpg");

                ImageViewAdapterInApply imageViewAdapterInApply = new ImageViewAdapterInApply(shopCartBeanApplyForDetail.getImgList());

                //就用横向的recyclerview
                RecyclerView gridViewRight = (RecyclerView) viewHeader.findViewById(R.id.gridviewinapplydetailright);
                gridViewRight.setLayoutManager(new MyLinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
                gridViewRight.setAdapter(imageViewAdapterInApply);
                imageViewAdapterInApply.notifyDataSetChanged();

                imageViewAdapterInApply.setOnItemClickListenerImageView(new OnItemClickListenerImageView() {

                    @Override
                    public void onItemClick(View view, int position) {

                        //点击查看大图内容
                        //单独的图片内容。
                        //2018年03月17日重新修改
                        Album.gallery(ApplyForDetailActivity.this)//
                                //.requestCode(2)//
                                .checkedList(datas)//
                                .currentPosition(position)//记录位置？
                                //.navigationAlpha(80)//
                                .checkable(false)//是否出现选择对勾内容//
                                .widget(//
                                        Widget.newLightBuilder(ApplyForDetailActivity.this)///
                                                .statusBarColor(Color.WHITE)
                                                .title("查看大图")//
                                                .build()//
                                )
                                .onResult(new Action<ArrayList<String>>() {
                                    @Override
                                    public void onAction(@NonNull ArrayList<String> result) {
                                        //  If it is optional, here you can accept the results of user selection.
                                    }//
                                })
                                .start();//

                    }
                });


            } else {

                layoutImageList.setVisibility(View.GONE);

            }


        }

        return viewHeader;
    }

    /**
     * 仅仅是做该底部recyclerview的条目点击事件
     */
    private interface OnItemClickListenerImageView {
        public abstract void onItemClick(View view, int position);
    }

    /**
     * 退货图片的九宫格内容
     */
    private class ImageViewAdapterInApply extends RecyclerView.Adapter<ImageViewAdapterInApply.ImageHolder> {

        private OnItemClickListenerImageView onItemClickListener;
        private ArrayList<ShopCartApplyForImageBean> filesReplace = new ArrayList<>();

        private void setOnItemClickListenerImageView(OnItemClickListenerImageView _onItemClickListener) {
            onItemClickListener = _onItemClickListener;
        }

        public ImageViewAdapterInApply(ArrayList<ShopCartApplyForImageBean> filesReplace) {
            this.filesReplace = filesReplace;
        }

        @NonNull
        @Override
        public ImageHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

            /*ImageView pview = new ImageView(ApplyForDetailActivity.this);
            //应该是减掉左侧文字和右侧间隔除以3 才是
            pview.setLayoutParams(new AbsListView.LayoutParams((int) (getResources().getDisplayMetrics().density * 60),//
                    (int) (getResources().getDisplayMetrics().density * 60)));//
            pview.setScaleType(ImageView.ScaleType.CENTER_CROP);//*/

            View view = LayoutInflater.from(Utils.getApp()).inflate(R.layout.applyimageright, parent, false);


            return new ImageHolder(view);
        }


        @Override
        public void onBindViewHolder(@NonNull ImageHolder holder, @SuppressLint("RecyclerView") int position) {

            //填充图片内容itchen做改造
            String imageUrl = filesReplace.get(position).getImgUrl();

            Glide.with(ApplyForDetailActivity.this)//
                    .asBitmap()//
                    .load(imageUrl.trim())//
                    //.transition(withCrossFade())//
                    .centerCrop()//
                    .fallback(R.drawable.iconerrorone)//
                    .error(R.drawable.iconerrorone)//
                    .placeholder(R.drawable.iconerrorone)//
                    .into(new BitmapImageViewTarget((ImageView) holder.imageView) {//这个是正常的九宫格图片内容。
                        @Override
                        protected void setResource(Bitmap resource) {//
                            super.setResource(resource);//
                            //圆角图片代码。
                        }
                    });

            if (onItemClickListener != null) {

                holder.imageView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        onItemClickListener.onItemClick(v, position);

                    }
                });

            }

        }

        @Override
        public int getItemCount() {
            return filesReplace.size();
        }

        class ImageHolder extends RecyclerView.ViewHolder {

            ImageView imageView;

            public ImageHolder(@NonNull View itemView) {
                super(itemView);

                imageView = (ImageView) itemView.findViewById(R.id.imageviewinapplydetailholder);


                //这里需要手动写一个TextView设置四个文字，计算宽度，然后减掉左右间距
                TextView textView = new TextView(Utils.getApp());
                textView.setText("退货凭证：");//如果是4个汉字是100.0，添加一个中文冒号是125.0；
                float with = textView.getPaint().measureText(textView.getText().toString());
                //LogUtils.d("itchen---宽度-->"+with);

                //重新设置高度和宽度
                ViewGroup.LayoutParams params = imageView.getLayoutParams();
                //params.width = (int) (((ScreenUtils.getScreenWidth() - (ConvertUtils.dp2px(14 + 8) + ConvertUtils.dp2px(14 + 8))) / 3));
                params.width = (int) (((ScreenUtils.getScreenWidth() - with - (ConvertUtils.dp2px(30) + ConvertUtils.dp2px(30))) / 3));
                params.height = params.width;//保持宽高一样的正方形

                //LogUtils.d("itchen---图片的宽度=>" + params.width);
                //itchen---图片的宽度=>181

                imageView.setLayoutParams(params);

            }
        }

    }


    @Override
    protected void gainDatas() {

        if (NetworkUtils.isConnected()) {

//            getDatasFromServer(returnApplyNoPass);

        } else {
            netWorkError();
        }

    }

//    private ApiRequestListener<JSONObject> apiRequestListener = new ApiRequestListener<JSONObject>() {
//        @Override
//        public void addLog(int what, Request<JSONObject> request, Map<String, Object> hashMap, String errorContent) {
//            CommUtils.addLog(what, request, hashMap, errorContent);
//        }
//
//        @Override
//        public void onStart(int method) {
//
//            switch (method) {
//
//                case ConstantApi.WHAT_APPLYFORDETAIL: {
//
//                    loadingGone();
//
//                    break;
//                }
//
//                default:
//                    break;
//            }
//
//        }
//
//        @Override
//        public void onSuccess(int method, Response<JSONObject> response, Request<JSONObject> request, Map<String, Object> hashMap) {
//
//            switch (method) {
//
//                case ConstantApi.WHAT_APPLYFORDETAIL: {
//
//                    ShopCartDatasApplyDetailTools shopCartDatasApplyDetailTools = //
//                            ShopCartDatasApplyDetailTools.getShopCartDatasApplyDetailTools(response.get().toString());
//
//                    if (shopCartDatasApplyDetailTools != null) {
//
//                        if (shopCartDatasApplyDetailTools.getCode() == ConstantApi.REQUEST_20000) {
//
//                            //清空列表 添加列表头 和列表尾
//                            if (mDatasResources != null && !mDatasResources.isEmpty()) {
//                                mDatasResources.clear();
//                            }
//
//                            if (applyForDetailAdapter != null) {
//                                applyForDetailAdapter.notifyDataSetChanged();
//                            }
//
//                            ShopCartBeanApplyForDetail shopCartBeanApplyForDetail = shopCartDatasApplyDetailTools.getData();
//
//                            mDatasResources.addAll(shopCartBeanApplyForDetail.getDetailVoList());
//
//                            //真实的放在这里的代码
//                            applyForDetailAdapter.removeAllHeaderView();
//                            applyForDetailAdapter.removeAllFooterView();
//                            applyForDetailAdapter.addHeaderView(getHeaderView(recyclerViewInapplyDetail, shopCartBeanApplyForDetail));
//
//                            if (returnIsVipOrder != 1) {
//                                applyForDetailAdapter.addFooterView(getFooterView(recyclerViewInapplyDetail, shopCartBeanApplyForDetail));
//                            } else {
//                                //会员商品，什么都不操作，不添加footer.
//                            }
//
//                            if (applyForDetailAdapter != null) {
//                                applyForDetailAdapter.notifyDataSetChanged();
//                            }
//
//                            //@applyState（等于0的时候可以取消申请；等于3代表退款完成，退款时间展示updateTime）
//                            //底部的【取消申请】的按钮是否展示的判断：
//                            //也就是说：是0才能【取消申请】，只要不是0，其余的状态都不能【取消申请】
//                            if (shopCartBeanApplyForDetail.getApplyState() != 0) {
//                                //不可以取消申请，那末就将【取消申请】布局隐藏
//                                layoutButtonInApplyDetail.setVisibility(View.GONE);
//                            } else {
//                                //可以取消申请,那末就将【取消申请】布局展示
//                                layoutButtonInApplyDetail.setVisibility(View.VISIBLE);
//                            }
//
//                        } else {
//                            apiRequestListener.onError(method, shopCartDatasApplyDetailTools.getCode(), shopCartDatasApplyDetailTools.getMessage());
//                            apiRequestListener.addLog(method, request, hashMap, CommUtils.addLogFormatCodeMessage(shopCartDatasApplyDetailTools.getCode(), shopCartDatasApplyDetailTools.getMessage()));
//
//                        }
//
//                    } else {
//
//                        //填充遮盖界面
//                        layoutButtonInApplyDetail.setVisibility(View.GONE);
//
//                        CommUtils.checkCurrently(ApplyForDetailActivity.this,//
//                                R.drawable.errororder,//
//                                "",//
//                                ConstantApi.CURRENTLYNODATA);//
//
//                    }
//
//                    break;
//                }
//
//                case ConstantApi.WHAT_APPLYFORDETAIL_CANCEL: {
//
//                    final SingleObjectTools singleObjectTools = SingleObjectTools.getSingleObject(response.get().toString());
//
//                    if (singleObjectTools != null) {
//                        //该接口返回数据形式：
//                        //{
//                        //	"code":"20000",
//                        //	"data":1,
//                        //	"message":"success"
//                        //}
//
//                        if (singleObjectTools.getCode() == ConstantApi.REQUEST_20000) {
//
//                            ToastUtils.make().setGravity(Gravity.CENTER, 0, 0);
//                            ToastUtils.showShort("取消成功~");
//
//                            //取消成功重新刷新该界面
//                            gainDatas();
//
//
//                        } else {
//                            apiRequestListener.onError(method, singleObjectTools.getCode(), singleObjectTools.getMessage());
//                            apiRequestListener.addLog(method, request, hashMap, CommUtils.addLogFormatCodeMessage(singleObjectTools.getCode(), singleObjectTools.getMessage()));
//
//                        }
//
//
//                    }
//
//
//                    break;
//                }
//
//                default:
//                    break;
//            }
//
//
//        }
//
//        @Override
//        public void onError(int method, int statusCode, String message) {
//
//            //如果查出来是无数据
//            switch (method) {
//
//                case ConstantApi.WHAT_APPLYFORDETAIL: {
//
//                    //获取详情内容
//                    CommTools.errorTokenOrEqument(mActivityInstance, statusCode, message, _sessionErrorActivity, new SequenceListener() {
//                        @Override
//                        public void doSomeThing() {
//                            CommUtils.onError(true, ApplyForDetailActivity.this, statusCode, message);
//                        }
//                    });
//
//                    break;
//                }
//
//                case ConstantApi.WHAT_APPLYFORDETAIL_CANCEL: {
//
//                    CommTools.errorTokenOrEqument(mActivityInstance, statusCode, message, _sessionErrorActivity, new SequenceListener() {
//                        @Override
//                        public void doSomeThing() {
//                            CommUtils.onError(true, ApplyForDetailActivity.this, statusCode, message);
//                        }
//                    });
//
//                    break;
//                }
//
//                default:
//                    break;
//            }
//
//
//        }
//    };

//    private HttpListener<JSONObject> httpListener = new HttpListener<JSONObject>() {
//
//        @Override
//        public void onSucceed(int what, Response<JSONObject> response, Request<JSONObject> request, Map<String, Object> hashMap) {
//
//            if (response.getHeaders().getResponseCode() == 200) {
//                apiRequestListener.onSuccess(what, response, request, hashMap);
//            } else {
//                //http报非200的报错内容
//                netWorkError();
//                //setEnableLoadmore(refreshLayoutInDetail,false);
//            }
//        }
//
//        @Override
//        public void onFailed(int what, Response<JSONObject> response, Request<JSONObject> request, Map<String, Object> hashMap) {
//
//            CommUtils.onFailed(ApplyForDetailActivity.this, ConstantApi.ONFAILED_PAGE, response);
//
//        }
//    };

    //取消申请退货的按钮内容
//    private void method_cancelApplyfor(String _returnApplyNo) {
//
//        //String requestUrl = Constants.getInstance().cancelReturnApply();
//        Request<JSONObject> request = NoHttp.createJsonObjectRequest(Constants.getInstance().cancelReturnApply(), RequestMethod.POST);
//
//        Map<String, Object> map = new HashMap<>();
//        map.put("returnApplyNo", _returnApplyNo);//退货的单号。 使用退货的单号直接来查询退货单 所有信息
//        request.setDefineRequestBodyForJson(JSON.toJSONString(map));
//
//        startRequest(ConstantApi.WHAT_APPLYFORDETAIL_CANCEL, request, map, httpListener, true, true);
//    }

    /**
     * 退货详情接口内容
     */
//    private void getDatasFromServer(String _returnApplyNo) {
//
//        //String requestUrl = Constants.getInstance().getReturnApplyDetail();
//        Request<JSONObject> request = NoHttp.createJsonObjectRequest(Constants.getInstance().getReturnApplyDetail(), RequestMethod.POST);
//
//        Map<String, Object> map = new HashMap<>();
//        map.put("returnApplyNo", _returnApplyNo);//退货的单号。 使用退货的单号直接来查询退货单 所有信息
//        request.setDefineRequestBodyForJson(JSON.toJSONString(map));
//
//        startRequest(ConstantApi.WHAT_APPLYFORDETAIL, request, map, httpListener, true, true);
//    }
    @Override
    protected void methodBack() {

        if (ActivityUtils.isActivityAlive(this)) {
            ActivityUtils.finishActivity(this);
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (!TextUtils.isEmpty(returnApplyNoPass)) {
            returnApplyNoPass = "";
        }

        returnIsVipOrder = 0;

        if (mAlertView != null) {
            if (mAlertView.isShowing()) {
                mAlertView.dismiss();
                mAlertView = null;
            }
        }

        if (mDatasResources != null && !mDatasResources.isEmpty()) {

            mDatasResources.clear();

            if (applyForDetailAdapter != null) {
                applyForDetailAdapter.notifyDataSetChanged();
            }

            applyForDetailAdapter = null;

        }

    }
}
